package com.infoauto.opc.gateway.opc;

import com.infoauto.opc.gateway.entity.*;
import com.infoauto.opc.gateway.model.gtm4.*;
import com.infoauto.opc.gateway.opc.model.MqttInterface;
import com.infoauto.opc.gateway.opc.model.MqttInterfaceNode;
import com.infoauto.opc.gateway.opc.utils.SpringContextUtils;
import com.infoauto.opc.gateway.service.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

//日志信息处理
public class LogMessageHandler {
    @Autowired
    private SpringContextUtils springContextUtils;
    /// <summary>
    /// Manager实例
    /// </summary>
    private static LogMessageHandler _manager;
    /// <summary>
    /// 锁定实例
    /// </summary>
    private static Object oClassLock = new Object();

    /// <summary>
    /// 得到该实例
    /// </summary>
    /// <returns></returns>
    public static LogMessageHandler Instance() {
        synchronized (oClassLock) //加锁只生成一个实例
        {
            if (_manager == null) {
                _manager = new LogMessageHandler();
            }
        }
        return _manager;
    }

    /// <summary>
    /// 私有的构造函数,防止从外部实例化
    /// </summary>
    private LogMessageHandler() {
    }

    /// <summary>
    /// 得到该实例
    /// </summary>
    public static LogMessageHandler This() {
        return Instance();
    }

    private final Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * MQ接口的消息处理中心
     **/
    public void LogProcessor(String topic, MqttInterface oi) {
        switch (topic) {
            case "check_the_number_of_units1":
            case "check_the_number_of_units2":
            case "check_the_number_of_units3":
            case "check_the_number_of_units4":
            case "check_the_number_of_units5":
            case "check_the_number_of_units6":
            case "check_the_number_of_units7":
            case "check_the_number_of_units8":
            case "check_the_number_of_units9":
            case "check_the_number_of_units10":
            case "check_the_number_of_units11":
            case "check_the_number_of_units12":
            case "check_the_number_of_units13":
            case "check_the_number_of_units14":
            case "check_the_number_of_units15":
            case "check_the_number_of_units16":
                this.saveCheckTheNumberOfUnits1(topic, oi);
                break;
            case "check_the_number_of_units17":
            case "check_the_number_of_units18":
            case "check_the_number_of_units19":
            case "check_the_number_of_units20":
            case "check_the_number_of_units21":
            case "check_the_number_of_units22":
            case "check_the_number_of_units23":
            case "check_the_number_of_units24":
            case "check_the_number_of_units25":
            case "check_the_number_of_units26":
            case "check_the_number_of_units27":
            case "check_the_number_of_units28":
            case "check_the_number_of_units29":
            case "check_the_number_of_units30":
            case "check_the_number_of_units31":
            case "check_the_number_of_units32":
                this.saveCheckTheNumberOfUnits2(topic, oi);
                break;
            case "check_the_process1":
            case "check_the_process2":
            case "check_the_process3":
            case "check_the_process4":
            case "check_the_process5":
            case "check_the_process6":
            case "check_the_process7":
            case "check_the_process8":
            case "check_the_process9":
            case "check_the_process10":
            case "check_the_process11":
            case "check_the_process12":
            case "check_the_process13":
            case "check_the_process14":
            case "check_the_process15":
            case "check_the_process16":
                this.saveCheckTheProcess(topic, oi);
                break;
            case "equipment_failure1":
            case "equipment_failure2":
            case "equipment_failure3":
            case "equipment_failure4":
            case "equipment_failure5":
            case "equipment_failure6":
            case "equipment_failure7":
            case "equipment_failure8":
            case "equipment_failure9":
            case "equipment_failure10":
            case "equipment_failure11":
            case "equipment_failure12":
            case "equipment_failure13":
            case "equipment_failure14":
            case "equipment_failure15":
            case "equipment_failure16":
                this.saveEquipmentFailure(topic, oi);
                break;
            case "hang_blow1":
            case "hang_blow2":
            case "hang_blow3":
            case "hang_blow4":
            case "hang_blow5":
            case "hang_blow6":
            case "hang_blow7":
            case "hang_blow8":
            case "hang_blow9":
            case "hang_blow10":
            case "hang_blow11":
            case "hang_blow12":
            case "hang_blow13":
            case "hang_blow14":
            case "hang_blow15":
            case "hang_blow16":
                this.saveHangBlow(topic, oi);
                break;
            case "spray1":
            case "spray2":
            case "spray3":
            case "spray4":
            case "spray5":
            case "spray6":
            case "spray7":
            case "spray8":
            case "spray9":
            case "spray10":
            case "spray11":
            case "spray12":
            case "spray13":
            case "spray14":
            case "spray15":
            case "spray16":
                this.saveSpray(topic, oi);
                break;
            default:
                break;
        }
    }


    private boolean saveCheckTheNumberOfUnits1(String topic, MqttInterface oi) {
        boolean flag = false;
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String productionTime = formatter.format(new Date()); //生产时间
            if (topic.equals("check_the_number_of_units1")) { //获取第一行数据
                Integer sn = 1; //顺序号
                this.saveData(oi, productionTime, Ctnou.S1001.getCode(), Ctnou.S1002.getCode(), Ctnou.S1003.getCode(), Ctnou.S1004.getCode(), Ctnou.S1005.getCode(), Ctnou.S1006.getCode(), Ctnou.S1007.getCode(), Ctnou.S1008.getCode(), Ctnou.S1009.getCode(), Ctnou.S1010.getCode(), Ctnou.S1011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units2")) { //获取第二行数据
                Integer sn = 2;
                this.saveData(oi, productionTime, Ctnou.S2001.getCode(), Ctnou.S2002.getCode(), Ctnou.S2003.getCode(), Ctnou.S2004.getCode(), Ctnou.S2005.getCode(), Ctnou.S2006.getCode(), Ctnou.S2007.getCode(), Ctnou.S2008.getCode(), Ctnou.S2009.getCode(), Ctnou.S2010.getCode(), Ctnou.S2011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units3")) { //获取第三行数据
                Integer sn = 3;
                this.saveData(oi, productionTime, Ctnou.S3001.getCode(), Ctnou.S3002.getCode(), Ctnou.S3003.getCode(), Ctnou.S3004.getCode(), Ctnou.S3005.getCode(), Ctnou.S3006.getCode(), Ctnou.S3007.getCode(), Ctnou.S3008.getCode(), Ctnou.S3009.getCode(), Ctnou.S3010.getCode(), Ctnou.S3011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units4")) { //获取第四行数据
                Integer sn = 4;
                this.saveData(oi, productionTime, Ctnou.S4001.getCode(), Ctnou.S4002.getCode(), Ctnou.S4003.getCode(), Ctnou.S4004.getCode(), Ctnou.S4005.getCode(), Ctnou.S4006.getCode(), Ctnou.S4007.getCode(), Ctnou.S4008.getCode(), Ctnou.S4009.getCode(), Ctnou.S4010.getCode(), Ctnou.S4011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units5")) { //获取第五行数据
                Integer sn = 5;
                this.saveData(oi, productionTime, Ctnou.S5001.getCode(), Ctnou.S5002.getCode(), Ctnou.S5003.getCode(), Ctnou.S5004.getCode(), Ctnou.S5005.getCode(), Ctnou.S5006.getCode(), Ctnou.S5007.getCode(), Ctnou.S5008.getCode(), Ctnou.S5009.getCode(), Ctnou.S5010.getCode(), Ctnou.S5011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units6")) { //获取第六行数据
                Integer sn = 6;
                this.saveData(oi, productionTime, Ctnou.S6001.getCode(), Ctnou.S6002.getCode(), Ctnou.S6003.getCode(), Ctnou.S6004.getCode(), Ctnou.S6005.getCode(), Ctnou.S6006.getCode(), Ctnou.S6007.getCode(), Ctnou.S6008.getCode(), Ctnou.S6009.getCode(), Ctnou.S6010.getCode(), Ctnou.S6011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units7")) { //获取第七行数据
                Integer sn = 7;
                this.saveData(oi, productionTime, Ctnou.S7001.getCode(), Ctnou.S7002.getCode(), Ctnou.S7003.getCode(), Ctnou.S7004.getCode(), Ctnou.S7005.getCode(), Ctnou.S7006.getCode(), Ctnou.S7007.getCode(), Ctnou.S7008.getCode(), Ctnou.S7009.getCode(), Ctnou.S7010.getCode(), Ctnou.S7011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units8")) { //获取第八行数据
                Integer sn = 8;
                this.saveData(oi, productionTime, Ctnou.S8001.getCode(), Ctnou.S8002.getCode(), Ctnou.S8003.getCode(), Ctnou.S8004.getCode(), Ctnou.S8005.getCode(), Ctnou.S8006.getCode(), Ctnou.S8007.getCode(), Ctnou.S8008.getCode(), Ctnou.S8009.getCode(), Ctnou.S8010.getCode(), Ctnou.S8011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units9")) { //获取第九行数据
                Integer sn = 9;
                this.saveData(oi, productionTime, Ctnou.S9001.getCode(), Ctnou.S9002.getCode(), Ctnou.S9003.getCode(), Ctnou.S9004.getCode(), Ctnou.S9005.getCode(), Ctnou.S9006.getCode(), Ctnou.S9007.getCode(), Ctnou.S9008.getCode(), Ctnou.S9009.getCode(), Ctnou.S9010.getCode(), Ctnou.S9011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units10")) { //获取第十行数据
                Integer sn = 10;
                this.saveData(oi, productionTime, Ctnou.S10001.getCode(), Ctnou.S10002.getCode(), Ctnou.S10003.getCode(), Ctnou.S10004.getCode(), Ctnou.S10005.getCode(), Ctnou.S10006.getCode(), Ctnou.S10007.getCode(), Ctnou.S10008.getCode(), Ctnou.S10009.getCode(), Ctnou.S10010.getCode(), Ctnou.S10011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units11")) { //获取第十一行数据
                Integer sn = 11;
                this.saveData(oi, productionTime, Ctnou.S11001.getCode(), Ctnou.S11002.getCode(), Ctnou.S11003.getCode(), Ctnou.S11004.getCode(), Ctnou.S11005.getCode(), Ctnou.S11006.getCode(), Ctnou.S11007.getCode(), Ctnou.S11008.getCode(), Ctnou.S11009.getCode(), Ctnou.S11010.getCode(), Ctnou.S11011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units12")) { //获取第十二行数据
                Integer sn = 12;
                this.saveData(oi, productionTime, Ctnou.S12001.getCode(), Ctnou.S12002.getCode(), Ctnou.S12003.getCode(), Ctnou.S12004.getCode(), Ctnou.S12005.getCode(), Ctnou.S12006.getCode(), Ctnou.S12007.getCode(), Ctnou.S12008.getCode(), Ctnou.S12009.getCode(), Ctnou.S12010.getCode(), Ctnou.S12011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units13")) { //获取第十三行数据
                Integer sn = 13;
                this.saveData(oi, productionTime, Ctnou.S13001.getCode(), Ctnou.S13002.getCode(), Ctnou.S13003.getCode(), Ctnou.S13004.getCode(), Ctnou.S13005.getCode(), Ctnou.S13006.getCode(), Ctnou.S13007.getCode(), Ctnou.S13008.getCode(), Ctnou.S13009.getCode(), Ctnou.S13010.getCode(), Ctnou.S13011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units14")) { //获取第十四行数据
                Integer sn = 14;
                this.saveData(oi, productionTime, Ctnou.S14001.getCode(), Ctnou.S14002.getCode(), Ctnou.S14003.getCode(), Ctnou.S14004.getCode(), Ctnou.S14005.getCode(), Ctnou.S14006.getCode(), Ctnou.S14007.getCode(), Ctnou.S14008.getCode(), Ctnou.S14009.getCode(), Ctnou.S14010.getCode(), Ctnou.S14011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units15")) { //获取第十五行数据
                Integer sn = 15;
                this.saveData(oi, productionTime, Ctnou.S15001.getCode(), Ctnou.S15002.getCode(), Ctnou.S15003.getCode(), Ctnou.S15004.getCode(), Ctnou.S15005.getCode(), Ctnou.S15006.getCode(), Ctnou.S15007.getCode(), Ctnou.S15008.getCode(), Ctnou.S15009.getCode(), Ctnou.S15010.getCode(), Ctnou.S15011.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units16")) { //获取第十六行数据
                Integer sn = 16;
                this.saveData(oi, productionTime, Ctnou.S16001.getCode(), Ctnou.S16002.getCode(), Ctnou.S16003.getCode(), Ctnou.S16004.getCode(), Ctnou.S16005.getCode(), Ctnou.S16006.getCode(), Ctnou.S16007.getCode(), Ctnou.S16008.getCode(), Ctnou.S16009.getCode(), Ctnou.S16010.getCode(), Ctnou.S16011.getCode(), sn);
            }
            flag = true;
        } catch (Exception ex) {
            logger.error("saveCheckTheNumberOfUnits1 method error = {}", ex.getMessage());
        }
        return flag;
    }

    private void saveData(MqttInterface oi, String productionTime, String s1, String s2, String s3, String s4, String s5, String s6, String s7, String s8, String s9, String s10, String s11, Integer sn) {
        try {
            CheckTheNumberOfUnits1 checkTheNumberOfUnits1 = new CheckTheNumberOfUnits1();
            CheckTheNumberOfUnits1Service checkTheNumberOfUnits1Service = springContextUtils.getBean(CheckTheNumberOfUnits1Service.class);
            Map<Integer, MqttInterfaceNode> map = oi.getNodes();
            ShiftService shiftService = springContextUtils.getBean(ShiftService.class);
            Shift shift = shiftService.selectByProductionTime(productionTime);//查询当前班次
            for (MqttInterfaceNode mqttInterfaceNode : map.values()) {
                if (mqttInterfaceNode.getTagName().equals(s1)) {
                    //时间带
                    checkTheNumberOfUnits1.setTimeZone(mqttInterfaceNode.getNodeValue() == null ? "" : mqttInterfaceNode.getNodeValue().getValue().toString());
                } else if (mqttInterfaceNode.getTagName().equals(s2)) {
                    //通过计划
                    checkTheNumberOfUnits1.setPassPlan(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s3)) {
                    //通过实际
                    checkTheNumberOfUnits1.setThroughActual(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s4)) {
                    //通过实际累积
                    checkTheNumberOfUnits1.setThroughActualAccumulation(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s5)) {
                    //通过可动率
                    checkTheNumberOfUnits1.setPassMobility(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s6)) {
                    //合格纯直行
                    checkTheNumberOfUnits1.setQualifiedPureStraight(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s7)) {
                    //合格擦摩
                    checkTheNumberOfUnits1.setWipeTheQualified(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s8)) {
                    //合格积累
                    checkTheNumberOfUnits1.setAccumulationOfQualified(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s9)) {
                    //不合格再涂装
                    checkTheNumberOfUnits1.setUnqualifiedReapply(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s10)) {
                    //不合格废弃
                    checkTheNumberOfUnits1.setUnqualifiedAbandonment(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s11)) {
                    //不合格积累
                    checkTheNumberOfUnits1.setNonconformingAccumulation(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                }
            }
            checkTheNumberOfUnits1.setSn(sn);//顺序号
            checkTheNumberOfUnits1.setProductionTime(productionTime);
            if(shift!=null){
                checkTheNumberOfUnits1.setShift(shift.getShift());
            }else{
                SimpleDateFormat formatter1 = new SimpleDateFormat("HH:mm:ss");
                Date date2 = formatter1.parse(formatter1.format(new Date()));
                Date date3 = formatter1.parse("17:30:00");//当前时间小于下午五点半时为班次1
                if (date2.getTime() - date3.getTime() > 0) {
                    checkTheNumberOfUnits1.setShift(2);
                } else {
                    checkTheNumberOfUnits1.setShift(1);
                }
            }
            //根据生产时间、班次、顺序号判重
            CheckTheNumberOfUnits1 ctno = checkTheNumberOfUnits1Service.select(checkTheNumberOfUnits1.getProductionTime(), checkTheNumberOfUnits1.getShift(), checkTheNumberOfUnits1.getSn());
            if (ctno != null) {
                checkTheNumberOfUnits1.setId(ctno.getId());
                checkTheNumberOfUnits1.setModifyDateTime(new Date());
                checkTheNumberOfUnits1.setRemark(ctno.getRemark());
                checkTheNumberOfUnits1Service.update(checkTheNumberOfUnits1);
            } else {
                checkTheNumberOfUnits1.setId(UUID.randomUUID().toString().replaceAll("-", ""));
                checkTheNumberOfUnits1.setCreateDateTime(new Date());
                checkTheNumberOfUnits1.setModifyDateTime(new Date());
                checkTheNumberOfUnits1.setCreateUser("SA");
                checkTheNumberOfUnits1.setModifyUser("SA");
                if (checkTheNumberOfUnits1.getProductionTime() != "" && checkTheNumberOfUnits1.getShift() != 0 && checkTheNumberOfUnits1.getSn() != 0) {
                    checkTheNumberOfUnits1Service.insert(checkTheNumberOfUnits1);
                }
            }
        } catch (ParseException e) {
            logger.error("saveData method error = {}", e.getMessage());
        }
    }

    private boolean saveCheckTheNumberOfUnits2(String topic, MqttInterface oi) {
        boolean flag = false;
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String productionTime = formatter.format(new Date()); //生产时间
            if (topic.equals("check_the_number_of_units17")) { //获取第一行数据
                Integer sn = 1; //顺序号
                this.saveCtnou2(oi, productionTime, Ctnou2.S1001.getCode(), Ctnou2.S1002.getCode(), Ctnou2.S1003.getCode(), Ctnou2.S1004.getCode(), Ctnou2.S1005.getCode(), Ctnou2.S1006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units18")) { //获取第二行数据
                Integer sn = 2;
                this.saveCtnou2(oi, productionTime, Ctnou2.S2001.getCode(), Ctnou2.S2002.getCode(), Ctnou2.S2003.getCode(), Ctnou2.S2004.getCode(), Ctnou2.S2005.getCode(), Ctnou2.S2006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units19")) { //获取第三行数据
                Integer sn = 3;
                this.saveCtnou2(oi, productionTime, Ctnou2.S3001.getCode(), Ctnou2.S3002.getCode(), Ctnou2.S3003.getCode(), Ctnou2.S3004.getCode(), Ctnou2.S3005.getCode(), Ctnou2.S3006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units20")) { //获取第四行数据
                Integer sn = 4;
                this.saveCtnou2(oi, productionTime, Ctnou2.S4001.getCode(), Ctnou2.S4002.getCode(), Ctnou2.S4003.getCode(), Ctnou2.S4004.getCode(), Ctnou2.S4005.getCode(), Ctnou2.S4006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units21")) { //获取第五行数据
                Integer sn = 5;
                this.saveCtnou2(oi, productionTime, Ctnou2.S5001.getCode(), Ctnou2.S5002.getCode(), Ctnou2.S5003.getCode(), Ctnou2.S5004.getCode(), Ctnou2.S5005.getCode(), Ctnou2.S5006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units22")) { //获取第六行数据
                Integer sn = 6;
                this.saveCtnou2(oi, productionTime, Ctnou2.S6001.getCode(), Ctnou2.S6002.getCode(), Ctnou2.S6003.getCode(), Ctnou2.S6004.getCode(), Ctnou2.S6005.getCode(), Ctnou2.S6006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units23")) { //获取第七行数据
                Integer sn = 7;
                this.saveCtnou2(oi, productionTime, Ctnou2.S7001.getCode(), Ctnou2.S7002.getCode(), Ctnou2.S7003.getCode(), Ctnou2.S7004.getCode(), Ctnou2.S7005.getCode(), Ctnou2.S7006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units24")) { //获取第八行数据
                Integer sn = 8;
                this.saveCtnou2(oi, productionTime, Ctnou2.S8001.getCode(), Ctnou2.S8002.getCode(), Ctnou2.S8003.getCode(), Ctnou2.S8004.getCode(), Ctnou2.S8005.getCode(), Ctnou2.S8006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units25")) { //获取第九行数据
                Integer sn = 9;
                this.saveCtnou2(oi, productionTime, Ctnou2.S9001.getCode(), Ctnou2.S9002.getCode(), Ctnou2.S9003.getCode(), Ctnou2.S9004.getCode(), Ctnou2.S9005.getCode(), Ctnou2.S9006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units26")) { //获取第十行数据
                Integer sn = 10;
                this.saveCtnou2(oi, productionTime, Ctnou2.S10001.getCode(), Ctnou2.S10002.getCode(), Ctnou2.S10003.getCode(), Ctnou2.S10004.getCode(), Ctnou2.S10005.getCode(), Ctnou2.S10006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units27")) { //获取第十一行数据
                Integer sn = 11;
                this.saveCtnou2(oi, productionTime, Ctnou2.S11001.getCode(), Ctnou2.S11002.getCode(), Ctnou2.S11003.getCode(), Ctnou2.S11004.getCode(), Ctnou2.S11005.getCode(), Ctnou2.S11006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units28")) { //获取第十二行数据
                Integer sn = 12;
                this.saveCtnou2(oi, productionTime, Ctnou2.S12001.getCode(), Ctnou2.S12002.getCode(), Ctnou2.S12003.getCode(), Ctnou2.S12004.getCode(), Ctnou2.S12005.getCode(), Ctnou2.S12006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units29")) { //获取第十三行数据
                Integer sn = 13;
                this.saveCtnou2(oi, productionTime, Ctnou2.S13001.getCode(), Ctnou2.S13002.getCode(), Ctnou2.S13003.getCode(), Ctnou2.S13004.getCode(), Ctnou2.S13005.getCode(), Ctnou2.S13006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units30")) { //获取第十四行数据
                Integer sn = 14;
                this.saveCtnou2(oi, productionTime, Ctnou2.S14001.getCode(), Ctnou2.S14002.getCode(), Ctnou2.S14003.getCode(), Ctnou2.S14004.getCode(), Ctnou2.S14005.getCode(), Ctnou2.S14006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units31")) { //获取第十五行数据
                Integer sn = 15;
                this.saveCtnou2(oi, productionTime, Ctnou2.S15001.getCode(), Ctnou2.S15002.getCode(), Ctnou2.S15003.getCode(), Ctnou2.S15004.getCode(), Ctnou2.S15005.getCode(), Ctnou2.S15006.getCode(), sn);
            } else if (topic.equals("check_the_number_of_units32")) { //获取第十六行数据
                Integer sn = 16;
                this.saveCtnou2(oi, productionTime, Ctnou2.S16001.getCode(), Ctnou2.S16002.getCode(), Ctnou2.S16003.getCode(), Ctnou2.S16004.getCode(), Ctnou2.S16005.getCode(), Ctnou2.S16006.getCode(), sn);
            }
            flag = true;
        } catch (Exception ex) {
            logger.error("saveCheckTheNumberOfUnits2 method error = {}", ex.getMessage());
        }
        return flag;
    }

    private void saveCtnou2(MqttInterface oi, String productionTime, String s1, String s2, String s3, String s4, String s5, String s6, Integer sn) {
        try {
            CheckTheNumberOfUnits2 checkTheNumberOfUnits2 = new CheckTheNumberOfUnits2();
            CheckTheNumberOfUnits2Service checkTheNumberOfUnits2Service = springContextUtils.getBean(CheckTheNumberOfUnits2Service.class);
            Map<Integer, MqttInterfaceNode> map = oi.getNodes();
            ShiftService shiftService = springContextUtils.getBean(ShiftService.class);
            Shift shift = shiftService.selectByProductionTime(productionTime);//查询当前班次
            for (MqttInterfaceNode mqttInterfaceNode : map.values()) {
                if (mqttInterfaceNode.getTagName().equals(s1)) {
                    //时间带
                    checkTheNumberOfUnits2.setTimeZone(mqttInterfaceNode.getNodeValue() == null ? "" : mqttInterfaceNode.getNodeValue().getValue().toString());
                } else if (mqttInterfaceNode.getTagName().equals(s2)) {
                    //直行率
                    checkTheNumberOfUnits2.setStraightRate(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s3)) {
                    //纯直行率
                    checkTheNumberOfUnits2.setRateOfPureStraight(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s4)) {
                    //再涂装率
                    checkTheNumberOfUnits2.setTheCoatingRateAgain(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s5)) {
                    //废品率
                    checkTheNumberOfUnits2.setRejectionRate(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s6)) {
                    //涂合效率
                    checkTheNumberOfUnits2.setCoatingEfficiency(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                }
            }
            checkTheNumberOfUnits2.setSn(sn);//顺序号
            checkTheNumberOfUnits2.setProductionTime(productionTime);
            if(shift!=null){
                checkTheNumberOfUnits2.setShift(shift.getShift());
            }else{
                SimpleDateFormat formatter1 = new SimpleDateFormat("HH:mm:ss");
                Date date2 = formatter1.parse(formatter1.format(new Date()));
                Date date3 = formatter1.parse("17:30:00");//当前时间小于下午五点半时为班次1
                if (date2.getTime() - date3.getTime() > 0) {
                    checkTheNumberOfUnits2.setShift(2);
                } else {
                    checkTheNumberOfUnits2.setShift(1);
                }
            }
            //根据生产时间、班次、顺序号判重
            CheckTheNumberOfUnits2 ctnou2 = checkTheNumberOfUnits2Service.select(checkTheNumberOfUnits2.getProductionTime(), checkTheNumberOfUnits2.getShift(), checkTheNumberOfUnits2.getSn());
            if (ctnou2 != null) {
                checkTheNumberOfUnits2.setId(ctnou2.getId());
                checkTheNumberOfUnits2.setModifyDateTime(new Date());
                checkTheNumberOfUnits2.setRemark(ctnou2.getRemark());
                checkTheNumberOfUnits2Service.update(checkTheNumberOfUnits2);
            } else {
                checkTheNumberOfUnits2.setId(UUID.randomUUID().toString().replaceAll("-", ""));
                checkTheNumberOfUnits2.setCreateDateTime(new Date());
                checkTheNumberOfUnits2.setModifyDateTime(new Date());
                checkTheNumberOfUnits2.setCreateUser("SA");
                checkTheNumberOfUnits2.setModifyUser("SA");
                if (checkTheNumberOfUnits2.getProductionTime() != "" && checkTheNumberOfUnits2.getShift() != 0 && checkTheNumberOfUnits2.getSn() != 0) {
                    checkTheNumberOfUnits2Service.insert(checkTheNumberOfUnits2);
                }
            }
        } catch (ParseException e) {
            logger.error("saveCtnou2 method error = {}", e.getMessage());
        }
    }

    private boolean saveCheckTheProcess(String topic, MqttInterface oi) {
        boolean flag = false;
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String productionTime = formatter.format(new Date()); //生产时间
            if (topic.equals("check_the_process1")) { //获取第一行数据
                Integer sn = 1; //顺序号
                this.saveCtp(oi, productionTime, Ctp.S1001.getCode(), Ctp.S1002.getCode(), Ctp.S1003.getCode(), Ctp.S1004.getCode(), Ctp.S1005.getCode(), Ctp.S1006.getCode(), Ctp.S1007.getCode(), Ctp.S1008.getCode(), Ctp.S1009.getCode(), Ctp.S1010.getCode(), Ctp.S1011.getCode(), Ctp.S1012.getCode(), Ctp.S1013.getCode(), Ctp.S1014.getCode(), Ctp.S1015.getCode(), Ctp.S1016.getCode(), sn);
            } else if (topic.equals("check_the_process2")) { //获取第二行数据
                Integer sn = 2;
                this.saveCtp(oi, productionTime, Ctp.S2001.getCode(), Ctp.S2002.getCode(), Ctp.S2003.getCode(), Ctp.S2004.getCode(), Ctp.S2005.getCode(), Ctp.S2006.getCode(), Ctp.S2007.getCode(), Ctp.S2008.getCode(), Ctp.S2009.getCode(), Ctp.S2010.getCode(), Ctp.S2011.getCode(), Ctp.S2012.getCode(), Ctp.S2013.getCode(), Ctp.S2014.getCode(), Ctp.S2015.getCode(), Ctp.S2016.getCode(), sn);
            } else if (topic.equals("check_the_process3")) { //获取第三行数据
                Integer sn = 3;
                this.saveCtp(oi, productionTime, Ctp.S3001.getCode(), Ctp.S3002.getCode(), Ctp.S3003.getCode(), Ctp.S3004.getCode(), Ctp.S3005.getCode(), Ctp.S3006.getCode(), Ctp.S3007.getCode(), Ctp.S3008.getCode(), Ctp.S3009.getCode(), Ctp.S3010.getCode(), Ctp.S3011.getCode(), Ctp.S3012.getCode(), Ctp.S3013.getCode(), Ctp.S3014.getCode(), Ctp.S3015.getCode(), Ctp.S3016.getCode(), sn);
            } else if (topic.equals("check_the_process4")) { //获取第四行数据
                Integer sn = 4;
                this.saveCtp(oi, productionTime, Ctp.S4001.getCode(), Ctp.S4002.getCode(), Ctp.S4003.getCode(), Ctp.S4004.getCode(), Ctp.S4005.getCode(), Ctp.S4006.getCode(), Ctp.S4007.getCode(), Ctp.S4008.getCode(), Ctp.S4009.getCode(), Ctp.S4010.getCode(), Ctp.S4011.getCode(), Ctp.S4012.getCode(), Ctp.S4013.getCode(), Ctp.S4014.getCode(), Ctp.S4015.getCode(), Ctp.S4016.getCode(), sn);
            } else if (topic.equals("check_the_process5")) { //获取第五行数据
                Integer sn = 5;
                this.saveCtp(oi, productionTime, Ctp.S5001.getCode(), Ctp.S5002.getCode(), Ctp.S5003.getCode(), Ctp.S5004.getCode(), Ctp.S5005.getCode(), Ctp.S5006.getCode(), Ctp.S5007.getCode(), Ctp.S5008.getCode(), Ctp.S5009.getCode(), Ctp.S5010.getCode(), Ctp.S5011.getCode(), Ctp.S5012.getCode(), Ctp.S5013.getCode(), Ctp.S5014.getCode(), Ctp.S5015.getCode(), Ctp.S5016.getCode(), sn);
            } else if (topic.equals("check_the_process6")) { //获取第六行数据
                Integer sn = 6;
                this.saveCtp(oi, productionTime, Ctp.S6001.getCode(), Ctp.S6002.getCode(), Ctp.S6003.getCode(), Ctp.S6004.getCode(), Ctp.S6005.getCode(), Ctp.S6006.getCode(), Ctp.S6007.getCode(), Ctp.S6008.getCode(), Ctp.S6009.getCode(), Ctp.S6010.getCode(), Ctp.S6011.getCode(), Ctp.S6012.getCode(), Ctp.S6013.getCode(), Ctp.S6014.getCode(), Ctp.S6015.getCode(), Ctp.S6016.getCode(), sn);
            } else if (topic.equals("check_the_process7")) { //获取第七行数据
                Integer sn = 7;
                this.saveCtp(oi, productionTime, Ctp.S7001.getCode(), Ctp.S7002.getCode(), Ctp.S7003.getCode(), Ctp.S7004.getCode(), Ctp.S7005.getCode(), Ctp.S7006.getCode(), Ctp.S7007.getCode(), Ctp.S7008.getCode(), Ctp.S7009.getCode(), Ctp.S7010.getCode(), Ctp.S7011.getCode(), Ctp.S7012.getCode(), Ctp.S7013.getCode(), Ctp.S7014.getCode(), Ctp.S7015.getCode(), Ctp.S7016.getCode(), sn);
            } else if (topic.equals("check_the_process8")) { //获取第八行数据
                Integer sn = 8;
                this.saveCtp(oi, productionTime, Ctp.S8001.getCode(), Ctp.S8002.getCode(), Ctp.S8003.getCode(), Ctp.S8004.getCode(), Ctp.S8005.getCode(), Ctp.S8006.getCode(), Ctp.S8007.getCode(), Ctp.S8008.getCode(), Ctp.S8009.getCode(), Ctp.S8010.getCode(), Ctp.S8011.getCode(), Ctp.S8012.getCode(), Ctp.S8013.getCode(), Ctp.S8014.getCode(), Ctp.S8015.getCode(), Ctp.S8016.getCode(), sn);
            } else if (topic.equals("check_the_process9")) { //获取第九行数据
                Integer sn = 9;
                this.saveCtp(oi, productionTime, Ctp.S9001.getCode(), Ctp.S9002.getCode(), Ctp.S9003.getCode(), Ctp.S9004.getCode(), Ctp.S9005.getCode(), Ctp.S9006.getCode(), Ctp.S9007.getCode(), Ctp.S9008.getCode(), Ctp.S9009.getCode(), Ctp.S9010.getCode(), Ctp.S9011.getCode(), Ctp.S9012.getCode(), Ctp.S9013.getCode(), Ctp.S9014.getCode(), Ctp.S9015.getCode(), Ctp.S9016.getCode(), sn);
            } else if (topic.equals("check_the_process10")) { //获取第十行数据
                Integer sn = 10;
                this.saveCtp(oi, productionTime, Ctp.S10001.getCode(), Ctp.S10002.getCode(), Ctp.S10003.getCode(), Ctp.S10004.getCode(), Ctp.S10005.getCode(), Ctp.S10006.getCode(), Ctp.S10007.getCode(), Ctp.S10008.getCode(), Ctp.S10009.getCode(), Ctp.S10010.getCode(), Ctp.S10011.getCode(), Ctp.S10012.getCode(), Ctp.S10013.getCode(), Ctp.S10014.getCode(), Ctp.S10015.getCode(), Ctp.S10016.getCode(), sn);
            } else if (topic.equals("check_the_process11")) { //获取第十一行数据
                Integer sn = 11;
                this.saveCtp(oi, productionTime, Ctp.S11001.getCode(), Ctp.S11002.getCode(), Ctp.S11003.getCode(), Ctp.S11004.getCode(), Ctp.S11005.getCode(), Ctp.S11006.getCode(), Ctp.S11007.getCode(), Ctp.S11008.getCode(), Ctp.S11009.getCode(), Ctp.S11010.getCode(), Ctp.S11011.getCode(), Ctp.S11012.getCode(), Ctp.S11013.getCode(), Ctp.S11014.getCode(), Ctp.S11015.getCode(), Ctp.S11016.getCode(), sn);
            } else if (topic.equals("check_the_process12")) { //获取第十二行数据
                Integer sn = 12;
                this.saveCtp(oi, productionTime, "P1-D800", "P1-D801", "P1-D802", "P1-D803", "P1-D804", "P1-D805", "P1-D806", "P1-D807", "P1-D808", "P1-D809", "P1-D80A", "", "", "", "", "", sn);
            } else if (topic.equals("check_the_process13")) { //获取第十三行数据
                Integer sn = 13;
                this.saveCtp(oi, productionTime, "P1-D800", "P1-D801", "P1-D802", "P1-D803", "P1-D804", "P1-D805", "P1-D806", "P1-D807", "P1-D808", "P1-D809", "P1-D80A", "", "", "", "", "", sn);
            } else if (topic.equals("check_the_process14")) { //获取第十四行数据
                Integer sn = 14;
                this.saveCtp(oi, productionTime, "P1-D800", "P1-D801", "P1-D802", "P1-D803", "P1-D804", "P1-D805", "P1-D806", "P1-D807", "P1-D808", "P1-D809", "P1-D80A", "", "", "", "", "", sn);
            } else if (topic.equals("check_the_process15")) { //获取第十五行数据
                Integer sn = 15;
                this.saveCtp(oi, productionTime, "P1-D800", "P1-D801", "P1-D802", "P1-D803", "P1-D804", "P1-D805", "P1-D806", "P1-D807", "P1-D808", "P1-D809", "P1-D80A", "", "", "", "", "", sn);
            } else if (topic.equals("check_the_process16")) { //获取第十六行数据
                Integer sn = 16;
                this.saveCtp(oi, productionTime, "P1-D800", "P1-D801", "P1-D802", "P1-D803", "P1-D804", "P1-D805", "P1-D806", "P1-D807", "P1-D808", "P1-D809", "P1-D80A", "", "", "", "", "", sn);
            }
            flag = true;
        } catch (Exception ex) {
            logger.error("saveCheckTheProcess method error = {}", ex.getMessage());
        }
        return flag;
    }

    private void saveCtp(MqttInterface oi, String productionTime, String s1, String s2, String s3, String s4, String s5, String s6, String s7, String s8, String s9, String s10, String s11, String s12, String s13, String s14, String s15, String s16, Integer sn) {
        try {
            CheckTheProcess checkTheProcess = new CheckTheProcess();
            CheckTheProcessService checkTheProcessService = springContextUtils.getBean(CheckTheProcessService.class);
            Map<Integer, MqttInterfaceNode> map = oi.getNodes();
            ShiftService shiftService = springContextUtils.getBean(ShiftService.class);
            Shift shift = shiftService.selectByProductionTime(productionTime);//查询当前班次
            for (MqttInterfaceNode mqttInterfaceNode : map.values()) {
                if (mqttInterfaceNode.getTagName().equals(s1)) {
                    //时间带
                    checkTheProcess.setTimeZone(mqttInterfaceNode.getNodeValue() == null ? "" : mqttInterfaceNode.getNodeValue().getValue().toString());
                } else if (mqttInterfaceNode.getTagName().equals(s2)) {
                    //喷房设备故障
                    checkTheProcess.setSprayEquipmentFailure(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s3)) {
                    //干燥炉设备故障
                    checkTheProcess.setDryingOvenEquipmentFailure(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s4)) {
                    //涂料温控设备故障
                    checkTheProcess.setCoatingTemperatureControlEquipmentFailure(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s5)) {
                    //计划
                    checkTheProcess.setPlan(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s6)) {
                    //实际
                    checkTheProcess.setActual(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s7)) {
                    //实际累积
                    checkTheProcess.setActualAccumlation(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s8)) {
                    //可动率
                    checkTheProcess.setMovableRate(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s9)) {
                    //欠车
                    checkTheProcess.setOweCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s10)) {
                    //满车
                    checkTheProcess.setFullCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s11)) {
                    //检查延迟1
                    checkTheProcess.setCheckDelay1(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s12)) {
                    //检查延迟2
                    checkTheProcess.setCheckDelay2(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s13)) {
                    //检查延迟3
                    checkTheProcess.setCheckDelay3(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s14)) {
                    //设备异常
                    checkTheProcess.setEquipmentAbnormal(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s15)) {
                    //计划停止
                    checkTheProcess.setPlanStop(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s16)) {
                    //ANDON入
                    checkTheProcess.setAndonIn(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                }

            }
            checkTheProcess.setSn(sn);//顺序号
            checkTheProcess.setProductionTime(productionTime);
            if(shift!=null){
                checkTheProcess.setShift(shift.getShift());
            }else {
                SimpleDateFormat formatter1 = new SimpleDateFormat("HH:mm:ss");
                Date date2 = formatter1.parse(formatter1.format(new Date()));
                Date date3 = formatter1.parse("17:30:00");//当前时间小于下午五点半时为班次1
                if (date2.getTime() - date3.getTime() > 0) {
                    checkTheProcess.setShift(2);
                } else {
                    checkTheProcess.setShift(1);
                }
            }
            //根据生产时间、班次、顺序号判重
            CheckTheProcess cps = checkTheProcessService.select(checkTheProcess.getProductionTime(), checkTheProcess.getShift(), checkTheProcess.getSn());
            if (cps != null) {
                checkTheProcess.setId(cps.getId());
                checkTheProcess.setModifyDateTime(new Date());
                checkTheProcess.setRemark(cps.getRemark());
                checkTheProcessService.update(checkTheProcess);
            } else {
                checkTheProcess.setId(UUID.randomUUID().toString().replaceAll("-", ""));
                checkTheProcess.setCreateDateTime(new Date());
                checkTheProcess.setModifyDateTime(new Date());
                checkTheProcess.setCreateUser("SA");
                checkTheProcess.setModifyUser("SA");
                if (checkTheProcess.getProductionTime() != "" && checkTheProcess.getShift() != 0 && checkTheProcess.getSn() != 0) {
                    checkTheProcessService.insert(checkTheProcess);
                }
            }
        } catch (ParseException e) {
            logger.error("saveCtp method error = {}", e.getMessage());
        }
    }

    private boolean saveEquipmentFailure(String topic, MqttInterface oi) {
        boolean flag = false;
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String productionTime = formatter.format(new Date()); //生产时间
            if (topic.equals("equipment_failure1")) { //获取第一行数据
                Integer sn = 1; //顺序号
                this.saveEf(oi, productionTime, Ef.S1001.getCode(), Ef.S1002.getCode(), Ef.S1003.getCode(), Ef.S1004.getCode(), Ef.S1005.getCode(), Ef.S1006.getCode(), Ef.S1007.getCode(), Ef.S1008.getCode(), Ef.S1009.getCode(), Ef.S1010.getCode(), sn);
            } else if (topic.equals("equipment_failure2")) { //获取第二行数据
                Integer sn = 2;
                this.saveEf(oi, productionTime, Ef.S2001.getCode(), Ef.S2002.getCode(), Ef.S2003.getCode(), Ef.S2004.getCode(), Ef.S2005.getCode(), Ef.S2006.getCode(), Ef.S2007.getCode(), Ef.S2008.getCode(), Ef.S2009.getCode(), Ef.S2010.getCode(), sn);
            } else if (topic.equals("equipment_failure3")) { //获取第三行数据
                Integer sn = 3;
                this.saveEf(oi, productionTime, Ef.S3001.getCode(), Ef.S3002.getCode(), Ef.S3003.getCode(), Ef.S3004.getCode(), Ef.S3005.getCode(), Ef.S3006.getCode(), Ef.S3007.getCode(), Ef.S3008.getCode(), Ef.S3009.getCode(), Ef.S3010.getCode(), sn);
            } else if (topic.equals("equipment_failure4")) { //获取第四行数据
                Integer sn = 4;
                this.saveEf(oi, productionTime, Ef.S4001.getCode(), Ef.S4002.getCode(), Ef.S4003.getCode(), Ef.S4004.getCode(), Ef.S4005.getCode(), Ef.S4006.getCode(), Ef.S4007.getCode(), Ef.S4008.getCode(), Ef.S4009.getCode(), Ef.S4010.getCode(), sn);
            } else if (topic.equals("equipment_failure5")) { //获取第五行数据
                Integer sn = 5;
                this.saveEf(oi, productionTime, Ef.S5001.getCode(), Ef.S5002.getCode(), Ef.S5003.getCode(), Ef.S5004.getCode(), Ef.S5005.getCode(), Ef.S5006.getCode(), Ef.S5007.getCode(), Ef.S5008.getCode(), Ef.S5009.getCode(), Ef.S5010.getCode(), sn);
            } else if (topic.equals("equipment_failure6")) { //获取第六行数据
                Integer sn = 6;
                this.saveEf(oi, productionTime, Ef.S6001.getCode(), Ef.S6002.getCode(), Ef.S6003.getCode(), Ef.S6004.getCode(), Ef.S6005.getCode(), Ef.S6006.getCode(), Ef.S6007.getCode(), Ef.S6008.getCode(), Ef.S6009.getCode(), Ef.S6010.getCode(), sn);
            } else if (topic.equals("equipment_failure7")) { //获取第七行数据
                Integer sn = 7;
                this.saveEf(oi, productionTime, Ef.S7001.getCode(), Ef.S7002.getCode(), Ef.S7003.getCode(), Ef.S7004.getCode(), Ef.S7005.getCode(), Ef.S7006.getCode(), Ef.S7007.getCode(), Ef.S7008.getCode(), Ef.S7009.getCode(), Ef.S7010.getCode(), sn);
            } else if (topic.equals("equipment_failure8")) { //获取第八行数据
                Integer sn = 8;
                this.saveEf(oi, productionTime, Ef.S8001.getCode(), Ef.S8002.getCode(), Ef.S8003.getCode(), Ef.S8004.getCode(), Ef.S8005.getCode(), Ef.S8006.getCode(), Ef.S8007.getCode(), Ef.S8008.getCode(), Ef.S8009.getCode(), Ef.S8010.getCode(), sn);
            } else if (topic.equals("equipment_failure9")) { //获取第九行数据
                Integer sn = 9;
                this.saveEf(oi, productionTime, Ef.S9001.getCode(), Ef.S9002.getCode(), Ef.S9003.getCode(), Ef.S9004.getCode(), Ef.S9005.getCode(), Ef.S9006.getCode(), Ef.S9007.getCode(), Ef.S9008.getCode(), Ef.S9009.getCode(), Ef.S9010.getCode(), sn);
            } else if (topic.equals("equipment_failure10")) { //获取第十行数据
                Integer sn = 10;
                this.saveEf(oi, productionTime, Ef.S10001.getCode(), Ef.S10002.getCode(), Ef.S10003.getCode(), Ef.S10004.getCode(), Ef.S10005.getCode(), Ef.S10006.getCode(), Ef.S10007.getCode(), Ef.S10008.getCode(), Ef.S10009.getCode(), Ef.S10010.getCode(), sn);
            } else if (topic.equals("equipment_failure11")) { //获取第十一行数据
                Integer sn = 11;
                this.saveEf(oi, productionTime, Ef.S11001.getCode(), Ef.S11002.getCode(), Ef.S11003.getCode(), Ef.S11004.getCode(), Ef.S11005.getCode(), Ef.S11006.getCode(), Ef.S11007.getCode(), Ef.S11008.getCode(), Ef.S11009.getCode(), Ef.S11010.getCode(), sn);
            } else if (topic.equals("equipment_failure12")) { //获取第十二行数据
                Integer sn = 12;
                this.saveEf(oi, productionTime, Ef.S12001.getCode(), Ef.S12002.getCode(), Ef.S12003.getCode(), Ef.S12004.getCode(), Ef.S12005.getCode(), Ef.S12006.getCode(), Ef.S12007.getCode(), Ef.S12008.getCode(), Ef.S12009.getCode(), Ef.S12010.getCode(), sn);
            } else if (topic.equals("equipment_failure13")) { //获取第十三行数据
                Integer sn = 13;
                this.saveEf(oi, productionTime, Ef.S13001.getCode(), Ef.S13002.getCode(), Ef.S13003.getCode(), Ef.S13004.getCode(), Ef.S13005.getCode(), Ef.S13006.getCode(), Ef.S13007.getCode(), Ef.S13008.getCode(), Ef.S13009.getCode(), Ef.S13010.getCode(), sn);
            } else if (topic.equals("equipment_failure14")) { //获取第十四行数据
                Integer sn = 14;
                this.saveEf(oi, productionTime, Ef.S14001.getCode(), Ef.S14002.getCode(), Ef.S14003.getCode(), Ef.S14004.getCode(), Ef.S14005.getCode(), Ef.S14006.getCode(), Ef.S14007.getCode(), Ef.S14008.getCode(), Ef.S14009.getCode(), Ef.S14010.getCode(), sn);
            } else if (topic.equals("equipment_failure15")) { //获取第十五行数据
                Integer sn = 15;
                this.saveEf(oi, productionTime, Ef.S15001.getCode(), Ef.S15002.getCode(), Ef.S15003.getCode(), Ef.S15004.getCode(), Ef.S15005.getCode(), Ef.S15006.getCode(), Ef.S15007.getCode(), Ef.S15008.getCode(), Ef.S15009.getCode(), Ef.S15010.getCode(), sn);
            } else if (topic.equals("equipment_failure16")) { //获取第十六行数据
                Integer sn = 16;
                this.saveEf(oi, productionTime, Ef.S16001.getCode(), Ef.S16002.getCode(), Ef.S16003.getCode(), Ef.S16004.getCode(), Ef.S16005.getCode(), Ef.S16006.getCode(), Ef.S16007.getCode(), Ef.S16008.getCode(), Ef.S16009.getCode(), Ef.S16010.getCode(), sn);
            }
            flag = true;
        } catch (Exception ex) {
            logger.error("saveEquipmentFailure method error = {}", ex.getMessage());
        }
        return flag;
    }

    private void saveEf(MqttInterface oi, String productionTime, String s1, String s2, String s3, String s4, String s5, String s6, String s7, String s8, String s9, String s10, Integer sn) {
        try {
            EquipmentFailure equipmentFailure = new EquipmentFailure();
            EquipmentFailureService equipmentFailureService = springContextUtils.getBean(EquipmentFailureService.class);
            Map<Integer, MqttInterfaceNode> map = oi.getNodes();
            ShiftService shiftService = springContextUtils.getBean(ShiftService.class);
            Shift shift = shiftService.selectByProductionTime(productionTime);//查询当前班次
            for (MqttInterfaceNode mqttInterfaceNode : map.values()) {
                if (mqttInterfaceNode.getTagName().equals(s1)) {
                    //时间带
                    equipmentFailure.setTimeZone(mqttInterfaceNode.getNodeValue() == null ? "" : mqttInterfaceNode.getNodeValue().getValue().toString());
                } else if (mqttInterfaceNode.getTagName().equals(s2)) {
                    //中涂工序
                    equipmentFailure.setCoatingProcess(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s3)) {
                    //色漆1工序
                    equipmentFailure.setPaint1Process(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s4)) {
                    //色漆2工序
                    equipmentFailure.setPaint2Process(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s5)) {
                    //清漆工序
                    equipmentFailure.setVarnishProcess(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s6)) {
                    //色差工序
                    equipmentFailure.setColorDifferenceProcess(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s7)) {
                    //检查工序
                    equipmentFailure.setCheckProcess(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s8)) {
                    //上挂工序
                    equipmentFailure.setHangProcess(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s9)) {
                    //吹气工序
                    equipmentFailure.setBlowProcess(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s10)) {
                    //干燥炉
                    equipmentFailure.setDryingOven(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                }

            }
            equipmentFailure.setSn(sn);//顺序号
            equipmentFailure.setProductionTime(productionTime);
            if(shift!=null){
                equipmentFailure.setShift(shift.getShift());
            }else {
                SimpleDateFormat formatter1 = new SimpleDateFormat("HH:mm:ss");
                Date date2 = formatter1.parse(formatter1.format(new Date()));
                Date date3 = formatter1.parse("17:30:00");//当前时间小于下午五点半时为班次1
                if (date2.getTime() - date3.getTime() > 0) {
                    equipmentFailure.setShift(2);
                } else {
                    equipmentFailure.setShift(1);
                }
            }
            //根据生产时间、班次、顺序号判重
            EquipmentFailure ef = equipmentFailureService.select(equipmentFailure.getProductionTime(), equipmentFailure.getShift(), equipmentFailure.getSn());
            if (ef != null) {
                equipmentFailure.setId(ef.getId());
                equipmentFailure.setModifyDateTime(new Date());
                equipmentFailure.setRemark(ef.getRemark());
                equipmentFailureService.update(equipmentFailure);
            } else {
                equipmentFailure.setId(UUID.randomUUID().toString().replaceAll("-", ""));
                equipmentFailure.setCreateDateTime(new Date());
                equipmentFailure.setModifyDateTime(new Date());
                equipmentFailure.setCreateUser("SA");
                equipmentFailure.setModifyUser("SA");
                if (equipmentFailure.getProductionTime() != "" && equipmentFailure.getShift() != 0 && equipmentFailure.getSn() != 0) {
                    equipmentFailureService.insert(equipmentFailure);
                }
            }
        } catch (ParseException e) {
            logger.error("saveEf method error = {}", e.getMessage());
        }
    }

    private boolean saveHangBlow(String topic, MqttInterface oi) {
        boolean flag = false;
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String productionTime = formatter.format(new Date()); //生产时间
            if (topic.equals("hang_blow1")) { //获取第一行数据
                Integer sn = 1; //顺序号
                this.saveHb(oi, productionTime, Hb.S1001.getCode(), Hb.S1002.getCode(), Hb.S1003.getCode(), Hb.S1004.getCode(), Hb.S1005.getCode(), Hb.S1006.getCode(), Hb.S1007.getCode(), Hb.S1008.getCode(), Hb.S1009.getCode(), Hb.S1010.getCode(), Hb.S1011.getCode(), Hb.S1012.getCode(), Hb.S1013.getCode(), sn);
            } else if (topic.equals("hang_blow2")) { //获取第二行数据
                Integer sn = 2;
                this.saveHb(oi, productionTime, Hb.S2001.getCode(), Hb.S2002.getCode(), Hb.S2003.getCode(), Hb.S2004.getCode(), Hb.S2005.getCode(), Hb.S2006.getCode(), Hb.S2007.getCode(), Hb.S2008.getCode(), Hb.S2009.getCode(), Hb.S2010.getCode(), Hb.S2011.getCode(), Hb.S2012.getCode(), Hb.S2013.getCode(), sn);
            } else if (topic.equals("hang_blow3")) { //获取第三行数据
                Integer sn = 3;
                this.saveHb(oi, productionTime, Hb.S3001.getCode(), Hb.S3002.getCode(), Hb.S3003.getCode(), Hb.S3004.getCode(), Hb.S3005.getCode(), Hb.S3006.getCode(), Hb.S3007.getCode(), Hb.S3008.getCode(), Hb.S3009.getCode(), Hb.S3010.getCode(), Hb.S3011.getCode(), Hb.S3012.getCode(), Hb.S3013.getCode(), sn);
            } else if (topic.equals("hang_blow4")) { //获取第四行数据
                Integer sn = 4;
                this.saveHb(oi, productionTime, Hb.S4001.getCode(), Hb.S4002.getCode(), Hb.S4003.getCode(), Hb.S4004.getCode(), Hb.S4005.getCode(), Hb.S4006.getCode(), Hb.S4007.getCode(), Hb.S4008.getCode(), Hb.S4009.getCode(), Hb.S4010.getCode(), Hb.S4011.getCode(), Hb.S4012.getCode(), Hb.S4013.getCode(), sn);
            } else if (topic.equals("hang_blow5")) { //获取第五行数据
                Integer sn = 5;
                this.saveHb(oi, productionTime, Hb.S5001.getCode(), Hb.S5002.getCode(), Hb.S5003.getCode(), Hb.S5004.getCode(), Hb.S5005.getCode(), Hb.S5006.getCode(), Hb.S5007.getCode(), Hb.S5008.getCode(), Hb.S5009.getCode(), Hb.S5010.getCode(), Hb.S5011.getCode(), Hb.S5012.getCode(), Hb.S5013.getCode(), sn);
            } else if (topic.equals("hang_blow6")) { //获取第六行数据
                Integer sn = 6;
                this.saveHb(oi, productionTime, Hb.S6001.getCode(), Hb.S6002.getCode(), Hb.S6003.getCode(), Hb.S6004.getCode(), Hb.S6005.getCode(), Hb.S6006.getCode(), Hb.S6007.getCode(), Hb.S6008.getCode(), Hb.S6009.getCode(), Hb.S6010.getCode(), Hb.S6011.getCode(), Hb.S6012.getCode(), Hb.S6013.getCode(), sn);
            } else if (topic.equals("hang_blow7")) { //获取第七行数据
                Integer sn = 7;
                this.saveHb(oi, productionTime, Hb.S7001.getCode(), Hb.S7002.getCode(), Hb.S7003.getCode(), Hb.S7004.getCode(), Hb.S7005.getCode(), Hb.S7006.getCode(), Hb.S7007.getCode(), Hb.S7008.getCode(), Hb.S7009.getCode(), Hb.S7010.getCode(), Hb.S7011.getCode(), Hb.S7012.getCode(), Hb.S7013.getCode(), sn);
            } else if (topic.equals("hang_blow8")) { //获取第八行数据
                Integer sn = 8;
                this.saveHb(oi, productionTime, Hb.S8001.getCode(), Hb.S8002.getCode(), Hb.S8003.getCode(), Hb.S8004.getCode(), Hb.S8005.getCode(), Hb.S8006.getCode(), Hb.S8007.getCode(), Hb.S8008.getCode(), Hb.S8009.getCode(), Hb.S8010.getCode(), Hb.S8011.getCode(), Hb.S8012.getCode(), Hb.S8013.getCode(), sn);
            } else if (topic.equals("hang_blow9")) { //获取第九行数据
                Integer sn = 9;
                this.saveHb(oi, productionTime, Hb.S9001.getCode(), Hb.S9002.getCode(), Hb.S9003.getCode(), Hb.S9004.getCode(), Hb.S9005.getCode(), Hb.S9006.getCode(), Hb.S9007.getCode(), Hb.S9008.getCode(), Hb.S9009.getCode(), Hb.S9010.getCode(), Hb.S9011.getCode(), Hb.S9012.getCode(), Hb.S9013.getCode(), sn);
            } else if (topic.equals("hang_blow10")) { //获取第十行数据
                Integer sn = 10;
                this.saveHb(oi, productionTime, Hb.S10001.getCode(), Hb.S10002.getCode(), Hb.S10003.getCode(), Hb.S10004.getCode(), Hb.S10005.getCode(), Hb.S10006.getCode(), Hb.S10007.getCode(), Hb.S10008.getCode(), Hb.S10009.getCode(), Hb.S10010.getCode(), Hb.S10011.getCode(), Hb.S10012.getCode(), Hb.S10013.getCode(), sn);
            } else if (topic.equals("hang_blow11")) { //获取第十一行数据
                Integer sn = 11;
                this.saveHb(oi, productionTime, Hb.S11001.getCode(), Hb.S11002.getCode(), Hb.S11003.getCode(), Hb.S11004.getCode(), Hb.S11005.getCode(), Hb.S11006.getCode(), Hb.S11007.getCode(), Hb.S11008.getCode(), Hb.S11009.getCode(), Hb.S11010.getCode(), Hb.S11011.getCode(), Hb.S11012.getCode(), Hb.S11013.getCode(), sn);
            } else if (topic.equals("hang_blow12")) { //获取第十二行数据
                Integer sn = 12;
                this.saveHb(oi, productionTime, Hb.S12001.getCode(), Hb.S12002.getCode(), Hb.S12003.getCode(), Hb.S12004.getCode(), Hb.S12005.getCode(), Hb.S12006.getCode(), Hb.S12007.getCode(), Hb.S12008.getCode(), Hb.S12009.getCode(), Hb.S12010.getCode(), Hb.S12011.getCode(), Hb.S12012.getCode(), Hb.S12013.getCode(), sn);
            } else if (topic.equals("hang_blow13")) { //获取第十三行数据
                Integer sn = 13;
                this.saveHb(oi, productionTime, Hb.S13001.getCode(), Hb.S13002.getCode(), Hb.S13003.getCode(), Hb.S13004.getCode(), Hb.S13005.getCode(), Hb.S13006.getCode(), Hb.S13007.getCode(), Hb.S13008.getCode(), Hb.S13009.getCode(), Hb.S13010.getCode(), Hb.S13011.getCode(), Hb.S13012.getCode(), Hb.S13013.getCode(), sn);
            } else if (topic.equals("equipment_failure14")) { //获取第十四行数据
                Integer sn = 14;
                this.saveHb(oi, productionTime, Hb.S14001.getCode(), Hb.S14002.getCode(), Hb.S14003.getCode(), Hb.S14004.getCode(), Hb.S14005.getCode(), Hb.S14006.getCode(), Hb.S14007.getCode(), Hb.S14008.getCode(), Hb.S14009.getCode(), Hb.S14010.getCode(), Hb.S14011.getCode(), Hb.S14012.getCode(), Hb.S14013.getCode(), sn);
            } else if (topic.equals("hang_blow14")) { //获取第十五行数据
                Integer sn = 15;
                this.saveHb(oi, productionTime, Hb.S15001.getCode(), Hb.S15002.getCode(), Hb.S15003.getCode(), Hb.S15004.getCode(), Hb.S15005.getCode(), Hb.S15006.getCode(), Hb.S15007.getCode(), Hb.S15008.getCode(), Hb.S15009.getCode(), Hb.S15010.getCode(), Hb.S15011.getCode(), Hb.S15012.getCode(), Hb.S15013.getCode(), sn);
            } else if (topic.equals("hang_blow15")) { //获取第十六行数据
                Integer sn = 16;
                this.saveHb(oi, productionTime, Hb.S16001.getCode(), Hb.S16002.getCode(), Hb.S16003.getCode(), Hb.S16004.getCode(), Hb.S16005.getCode(), Hb.S16006.getCode(), Hb.S16007.getCode(), Hb.S16008.getCode(), Hb.S16009.getCode(), Hb.S16010.getCode(), Hb.S16011.getCode(), Hb.S16012.getCode(), Hb.S16013.getCode(), sn);
            }
            flag = true;
        } catch (Exception ex) {
            logger.error("saveHangBlow method error = {}", ex.getMessage());
        }
        return flag;
    }

    private void saveHb(MqttInterface oi, String productionTime, String s1, String s2, String s3, String s4, String s5, String s6, String s7, String s8, String s9, String s10, String s11, String s12, String s13, Integer sn) {
        try {
            HangBlow hangBlow = new HangBlow();
            HangBlowService hangBlowService = springContextUtils.getBean(HangBlowService.class);
            Map<Integer, MqttInterfaceNode> map = oi.getNodes();
            ShiftService shiftService = springContextUtils.getBean(ShiftService.class);
            Shift shift = shiftService.selectByProductionTime(productionTime);//查询当前班次
            for (MqttInterfaceNode mqttInterfaceNode : map.values()) {
                if (mqttInterfaceNode.getTagName().equals(s1)) {
                    //时间带
                    hangBlow.setTimeZone(mqttInterfaceNode.getNodeValue() == null ? "" : mqttInterfaceNode.getNodeValue().getValue().toString());
                } else if (mqttInterfaceNode.getTagName().equals(s2)) {
                    //上挂欠车
                    hangBlow.setHangOweCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s3)) {
                    //上挂满车
                    hangBlow.setHangFullCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s4)) {
                    //上挂设备异常
                    hangBlow.setHangEquipmentAbnormal(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s5)) {
                    //吹气欠车
                    hangBlow.setBlowOweCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s6)) {
                    //吹气满车
                    hangBlow.setBlowFullCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s7)) {
                    //吹气延迟
                    hangBlow.setBlowDelay(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s8)) {
                    //吹气设备异常
                    hangBlow.setBlowEquipmentBanormal(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s9)) {
                    //存储区欠车
                    hangBlow.setStorageAreaOweCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s10)) {
                    //存储区满车
                    hangBlow.setStorageAreaFullCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s11)) {
                    //存储区设备异常
                    hangBlow.setStorageAreaEquipmentBanormal(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s12)) {
                    //计划停止
                    hangBlow.setPlanStop(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s13)) {
                    //ANDON入
                    hangBlow.setAndonIn(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                }

            }
            hangBlow.setSn(sn);//顺序号
            hangBlow.setProductionTime(productionTime);
            if(shift!=null){
                hangBlow.setShift(shift.getShift());
            }else{
                SimpleDateFormat formatter1 = new SimpleDateFormat("HH:mm:ss");
                Date date2 = formatter1.parse(formatter1.format(new Date()));
                Date date3 = formatter1.parse("17:30:00");//当前时间小于下午五点半时为班次1
                if (date2.getTime() - date3.getTime() > 0) {
                    hangBlow.setShift(2);
                } else {
                    hangBlow.setShift(1);
                }
            }
            //根据生产时间、班次、顺序号判重
            HangBlow hb = hangBlowService.select(hangBlow.getProductionTime(), hangBlow.getShift(), hangBlow.getSn());
            if (hb != null) {
                hangBlow.setId(hb.getId());
                hangBlow.setModifyDateTime(new Date());
                hangBlow.setRemark(hb.getRemark());
                hangBlowService.update(hangBlow);
            } else {
                hangBlow.setId(UUID.randomUUID().toString().replaceAll("-", ""));
                hangBlow.setCreateDateTime(new Date());
                hangBlow.setModifyDateTime(new Date());
                hangBlow.setCreateUser("SA");
                hangBlow.setModifyUser("SA");
                if (hangBlow.getProductionTime() != "" && hangBlow.getShift() != 0 && hangBlow.getSn() != 0) {
                    hangBlowService.insert(hangBlow);
                }
            }
        } catch (ParseException e) {
            logger.error("saveHb method error = {}", e.getMessage());
        }
    }

    private boolean saveSpray(String topic, MqttInterface oi) {
        boolean flag = false;
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String productionTime = formatter.format(new Date()); //生产时间
            if (topic.equals("spray1")) { //获取第一行数据
                Integer sn = 1; //顺序号
                this.saveSp(oi, productionTime, Sp.S1001.getCode(), Sp.S1002.getCode(), Sp.S1003.getCode(), Sp.S1004.getCode(), Sp.S1005.getCode(), Sp.S1006.getCode(), Sp.S1007.getCode(), Sp.S1008.getCode(), Sp.S1009.getCode(), Sp.S1010.getCode(), Sp.S1011.getCode(), Sp.S1012.getCode(), Sp.S1013.getCode(), Sp.S1014.getCode(), Sp.S1015.getCode(), sn);
            } else if (topic.equals("spray2")) { //获取第二行数据
                Integer sn = 2;
                this.saveSp(oi, productionTime, Sp.S2001.getCode(), Sp.S2002.getCode(), Sp.S2003.getCode(), Sp.S2004.getCode(), Sp.S2005.getCode(), Sp.S2006.getCode(), Sp.S2007.getCode(), Sp.S2008.getCode(), Sp.S2009.getCode(), Sp.S2010.getCode(), Sp.S2011.getCode(), Sp.S2012.getCode(), Sp.S2013.getCode(), Sp.S2014.getCode(), Sp.S2015.getCode(), sn);
            } else if (topic.equals("spray3")) { //获取第三行数据
                Integer sn = 3;
                this.saveSp(oi, productionTime, Sp.S3001.getCode(), Sp.S3002.getCode(), Sp.S3003.getCode(), Sp.S3004.getCode(), Sp.S3005.getCode(), Sp.S3006.getCode(), Sp.S3007.getCode(), Sp.S3008.getCode(), Sp.S3009.getCode(), Sp.S3010.getCode(), Sp.S3011.getCode(), Sp.S3012.getCode(), Sp.S3013.getCode(), Sp.S3014.getCode(), Sp.S3015.getCode(), sn);
            } else if (topic.equals("spray4")) { //获取第四行数据
                Integer sn = 4;
                this.saveSp(oi, productionTime, Sp.S4001.getCode(), Sp.S4002.getCode(), Sp.S4003.getCode(), Sp.S4004.getCode(), Sp.S4005.getCode(), Sp.S4006.getCode(), Sp.S4007.getCode(), Sp.S4008.getCode(), Sp.S4009.getCode(), Sp.S4010.getCode(), Sp.S4011.getCode(), Sp.S4012.getCode(), Sp.S4013.getCode(), Sp.S4014.getCode(), Sp.S4015.getCode(), sn);
            } else if (topic.equals("spray5")) { //获取第五行数据
                Integer sn = 5;
                this.saveSp(oi, productionTime, Sp.S5001.getCode(), Sp.S5002.getCode(), Sp.S5003.getCode(), Sp.S5004.getCode(), Sp.S5005.getCode(), Sp.S5006.getCode(), Sp.S5007.getCode(), Sp.S5008.getCode(), Sp.S5009.getCode(), Sp.S5010.getCode(), Sp.S5011.getCode(), Sp.S5012.getCode(), Sp.S5013.getCode(), Sp.S5014.getCode(), Sp.S5015.getCode(), sn);
            } else if (topic.equals("spray6")) { //获取第六行数据
                Integer sn = 6;
                this.saveSp(oi, productionTime, Sp.S6001.getCode(), Sp.S6002.getCode(), Sp.S6003.getCode(), Sp.S6004.getCode(), Sp.S6005.getCode(), Sp.S6006.getCode(), Sp.S6007.getCode(), Sp.S6008.getCode(), Sp.S6009.getCode(), Sp.S6010.getCode(), Sp.S6011.getCode(), Sp.S6012.getCode(), Sp.S6013.getCode(), Sp.S6014.getCode(), Sp.S6015.getCode(), sn);
            } else if (topic.equals("spray7")) { //获取第七行数据
                Integer sn = 7;
                this.saveSp(oi, productionTime, Sp.S7001.getCode(), Sp.S7002.getCode(), Sp.S7003.getCode(), Sp.S7004.getCode(), Sp.S7005.getCode(), Sp.S7006.getCode(), Sp.S7007.getCode(), Sp.S7008.getCode(), Sp.S7009.getCode(), Sp.S7010.getCode(), Sp.S7011.getCode(), Sp.S7012.getCode(), Sp.S7013.getCode(), Sp.S7014.getCode(), Sp.S7015.getCode(), sn);
            } else if (topic.equals("spray8")) { //获取第八行数据
                Integer sn = 8;
                this.saveSp(oi, productionTime, Sp.S8001.getCode(), Sp.S8002.getCode(), Sp.S8003.getCode(), Sp.S8004.getCode(), Sp.S8005.getCode(), Sp.S8006.getCode(), Sp.S8007.getCode(), Sp.S8008.getCode(), Sp.S8009.getCode(), Sp.S8010.getCode(), Sp.S8011.getCode(), Sp.S8012.getCode(), Sp.S8013.getCode(), Sp.S8014.getCode(), Sp.S8015.getCode(), sn);
            } else if (topic.equals("spray9")) { //获取第九行数据
                Integer sn = 9;
                this.saveSp(oi, productionTime, Sp.S9001.getCode(), Sp.S9002.getCode(), Sp.S9003.getCode(), Sp.S9004.getCode(), Sp.S9005.getCode(), Sp.S9006.getCode(), Sp.S9007.getCode(), Sp.S9008.getCode(), Sp.S9009.getCode(), Sp.S9010.getCode(), Sp.S9011.getCode(), Sp.S9012.getCode(), Sp.S9013.getCode(), Sp.S9014.getCode(), Sp.S9015.getCode(), sn);
            } else if (topic.equals("spray10")) { //获取第十行数据
                Integer sn = 10;
                this.saveSp(oi, productionTime, Sp.S10001.getCode(), Sp.S10002.getCode(), Sp.S10003.getCode(), Sp.S10004.getCode(), Sp.S10005.getCode(), Sp.S10006.getCode(), Sp.S10007.getCode(), Sp.S10008.getCode(), Sp.S10009.getCode(), Sp.S10010.getCode(), Sp.S10011.getCode(), Sp.S10012.getCode(), Sp.S10013.getCode(), Sp.S10014.getCode(), Sp.S10015.getCode(), sn);
            } else if (topic.equals("spray11")) { //获取第十一行数据
                Integer sn = 11;
                this.saveSp(oi, productionTime, Sp.S11001.getCode(), Sp.S11002.getCode(), Sp.S11003.getCode(), Sp.S11004.getCode(), Sp.S11005.getCode(), Sp.S11006.getCode(), Sp.S11007.getCode(), Sp.S11008.getCode(), Sp.S11009.getCode(), Sp.S11010.getCode(), Sp.S11011.getCode(), Sp.S11012.getCode(), Sp.S11013.getCode(), Sp.S11014.getCode(), Sp.S11015.getCode(), sn);
            } else if (topic.equals("spray12")) { //获取第十二行数据
                Integer sn = 12;
                this.saveSp(oi, productionTime, Sp.S12001.getCode(), Sp.S12002.getCode(), Sp.S12003.getCode(), Sp.S12004.getCode(), Sp.S12005.getCode(), Sp.S12006.getCode(), Sp.S12007.getCode(), Sp.S12008.getCode(), Sp.S12009.getCode(), Sp.S12010.getCode(), Sp.S12011.getCode(), Sp.S12012.getCode(), Sp.S12013.getCode(), Sp.S12014.getCode(), Sp.S12015.getCode(), sn);
            } else if (topic.equals("spray13")) { //获取第十三行数据
                Integer sn = 13;
                this.saveSp(oi, productionTime, Sp.S13001.getCode(), Sp.S13002.getCode(), Sp.S13003.getCode(), Sp.S13004.getCode(), Sp.S13005.getCode(), Sp.S13006.getCode(), Sp.S13007.getCode(), Sp.S13008.getCode(), Sp.S13009.getCode(), Sp.S13010.getCode(), Sp.S13011.getCode(), Sp.S13012.getCode(), Sp.S13013.getCode(), Sp.S13014.getCode(), Sp.S13015.getCode(), sn);
            } else if (topic.equals("spray14")) { //获取第十四行数据
                Integer sn = 14;
                this.saveSp(oi, productionTime, Sp.S14001.getCode(), Sp.S14002.getCode(), Sp.S14003.getCode(), Sp.S14004.getCode(), Sp.S14005.getCode(), Sp.S14006.getCode(), Sp.S14007.getCode(), Sp.S14008.getCode(), Sp.S14009.getCode(), Sp.S14010.getCode(), Sp.S14011.getCode(), Sp.S14012.getCode(), Sp.S14013.getCode(), Sp.S14014.getCode(), Sp.S14015.getCode(), sn);
            } else if (topic.equals("spray15")) { //获取第十五行数据
                Integer sn = 15;
                this.saveSp(oi, productionTime, Sp.S15001.getCode(), Sp.S15002.getCode(), Sp.S15003.getCode(), Sp.S15004.getCode(), Sp.S15005.getCode(), Sp.S15006.getCode(), Sp.S15007.getCode(), Sp.S15008.getCode(), Sp.S15009.getCode(), Sp.S15010.getCode(), Sp.S15011.getCode(), Sp.S15012.getCode(), Sp.S15013.getCode(), Sp.S15014.getCode(), Sp.S15015.getCode(), sn);
            } else if (topic.equals("spray16")) { //获取第十六行数据
                Integer sn = 16;
                this.saveSp(oi, productionTime, Sp.S16001.getCode(), Sp.S16002.getCode(), Sp.S16003.getCode(), Sp.S16004.getCode(), Sp.S16005.getCode(), Sp.S16006.getCode(), Sp.S16007.getCode(), Sp.S16008.getCode(), Sp.S16009.getCode(), Sp.S16010.getCode(), Sp.S16011.getCode(), Sp.S16012.getCode(), Sp.S16013.getCode(), Sp.S16014.getCode(), Sp.S16015.getCode(), sn);
            }
            flag = true;
        } catch (Exception ex) {
            logger.error("saveSpray method error = {}", ex.getMessage());
        }
        return flag;
    }

    private void saveSp(MqttInterface oi, String productionTime, String s1, String s2, String s3, String s4, String s5, String s6, String s7, String s8, String s9, String s10, String s11, String s12, String s13, String s14, String s15, Integer sn) {
        try {
            Spray spray = new Spray();
            SprayService sprayService = springContextUtils.getBean(SprayService.class);
            Map<Integer, MqttInterfaceNode> map = oi.getNodes();
            ShiftService shiftService = springContextUtils.getBean(ShiftService.class);
            Shift shift = shiftService.selectByProductionTime(productionTime);//查询当前班次
            for (MqttInterfaceNode mqttInterfaceNode : map.values()) {
                if (mqttInterfaceNode.getTagName().equals(s1)) {
                    //时间带
                    spray.setTimeZone(mqttInterfaceNode.getNodeValue() == null ? "" : mqttInterfaceNode.getNodeValue().getValue().toString());
                } else if (mqttInterfaceNode.getTagName().equals(s2)) {
                    //上挂欠车
                    spray.setMidwayOweCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s3)) {
                    //上挂满车
                    spray.setMidwayFullCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s4)) {
                    //上挂设备异常
                    spray.setMidwayEquipmentBanormal(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s5)) {
                    //吹气欠车
                    spray.setPaint1OweCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s6)) {
                    //吹气满车
                    spray.setPaint1FullCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s7)) {
                    //吹气延迟
                    spray.setPaint1EquipmentBanormal(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s8)) {
                    //吹气设备异常
                    spray.setPaint2OweCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s9)) {
                    //存储区欠车
                    spray.setPaint2FullCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s10)) {
                    //存储区满车
                    spray.setPaint2EquipmentBanormal(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s11)) {
                    //存储区设备异常
                    spray.setVarnishOweCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s12)) {
                    //存储区设备异常
                    spray.setVarnishFullCar(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s13)) {
                    //存储区设备异常
                    spray.setVarnishEquipmentBanormal(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s14)) {
                    //计划停止
                    spray.setPlanStop(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                } else if (mqttInterfaceNode.getTagName().equals(s15)) {
                    //ANDON入
                    spray.setAndonIn(mqttInterfaceNode.getNodeValue() == null ? 0 : Integer.parseInt(mqttInterfaceNode.getNodeValue().getValue().toString()));
                }

            }
            spray.setSn(sn);//顺序号
            spray.setProductionTime(productionTime);
            if(shift!=null){
                spray.setShift(shift.getShift());
            }else{
                SimpleDateFormat formatter1 = new SimpleDateFormat("HH:mm:ss");
                Date date2 = formatter1.parse(formatter1.format(new Date()));
                Date date3 = formatter1.parse("17:30:00");//当前时间小于下午五点半时为班次1
                if (date2.getTime() - date3.getTime() > 0) {
                    spray.setShift(2);
                } else {
                    spray.setShift(1);
                }
            }
            //根据生产时间、班次、顺序号判重
            Spray sp = sprayService.select(spray.getProductionTime(), spray.getShift(), spray.getSn());
            if (sp != null) {
                spray.setId(sp.getId());
                spray.setModifyDateTime(new Date());
                spray.setRemark(sp.getRemark());
                sprayService.update(spray);
            } else {
                spray.setId(UUID.randomUUID().toString().replaceAll("-", ""));
                spray.setCreateDateTime(new Date());
                spray.setModifyDateTime(new Date());
                spray.setCreateUser("SA");
                spray.setModifyUser("SA");
                if (spray.getProductionTime() != "" && spray.getShift() != 0 && spray.getSn() != 0) {
                    sprayService.insert(spray);
                }
            }
        } catch (ParseException e) {
            logger.error("saveSp method error = {}", e.getMessage());
        }
    }
}
